package com.hmjk.health.background;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.hmjk.health.util.RSAUtils;

import android.util.Log;

public class HTTPREQ {
	public static final String CMD_SIGN_IN = "CMD_SIGN_IN";
	public static final String CMD_SIGN_OUT = "CMD_SIGN_OUT";
	public static final String CMD_VALIDATE_ACCOUNT = "CMD_VALIDATE_ACCOUNT";
	//public static final String CMD_VALIDATE_PHONE = "CMD_VALIDATE_PHONE";
	public static final String CMD_GET_IDENTIFY_CODE = "CMD_GET_IDENTIFY_CODE";
	public static final String CMD_SIGN_UP = "CMD_SIGN_UP";
	public static final String CMD_CHANGE_PASSWORD = "CMD_CHANGE_PASSWORD";
	public static final String CMD_RETRIEVE_PASSWORD = "CMD_RETRIEVE_PASSWORD";
	public static final String CMD_GET_USERDATA = "CMD_GET_USERDATA";
	public static final String CMD_CHECK_USERFACE = "CMD_GET_USERFACE";
	public static final String CMD_DOWNLOAD_USERFACE = "CMD_DOWNLOAD_USERFACE";
	public static final String CMD_GET_FA_DETAIL = "CMD_GET_FA_DETAIL";
	public static final String CMD_GET_FA_LIST = "CMD_GET_FA_LIST";
	public static final String CMD_GET_DEV_LIST = "CMD_GET_DEV_LIST";
	public static final String CMD_CHECK_DEVFACE = "CMD_CHECK_DEVFACE";
	public static final String CMD_GET_FAMEMBERS = "CMD_GET_FAMEMBERS";
	public static final String CMD_COMMIT_USERDATA = "CMD_COMMIT_USERDATA";
	public static final String CMD_COMMIT_BUILDFAMILY = "CMD_COMMIT_BUILDFAMILY";
	public static final String CMD_APPLY_JOIN_FA = "CMD_APPLY_JOIN_FA";
	public static final String CMD_COMMIT_ADMIN_FA = "CMD_COMMIT_ADMIN_FA";
	public static final String CMD_COMMIT_ABORT_BY_ADMIN_FA = "CMD_COMMIT_ABORT_BY_ADMIN_FA";
	public static final String CMD_COMMIT_ABORT_BY_MEMBER_FA = "CMD_COMMIT_ABORT_BY_MEMBER_FA";
	public static final String CMD_COMMIT_FA_DETAIL = "CMD_COMMIT_FA_DETAIL";
	public static final String CMD_GET_DEVSETTINGS = "CMD_GET_DEVSETTINGS";
	public static final String CMD_GET_DEVPOWER = "CMD_GET_DEVPOWER";
	public static final String CMD_QUERY_LOCATION_PAGE = "CMD_QUERY_LOCATION_PAGE";
	//public static final String CMD_QUERY_LOCATION_COUNT = "CMD_QUERY_LOCATION_COUNT"; //api defined but we haddent used it.
	public static final String CMD_QUERY_LOCATION_NEWEST = "CMD_QUERY_LOCATION_NEWEST";
	public static final String CMD_ADD_NEW_DEVICE = "CMD_ADD_NEW_DEVICE";
	public static final String CMD_ACTIVATE_DEVICE = "CMD_ACTIVATE_DEVICE";
	public static final String CMD_UPDATE_DEVICE_NAME = "CMD_UPDATE_DEVICE_NAME";
	public static final String CMD_APPLY_INTEREST_DEV = "CMD_APPLY_INTEREST_DEV";
	public static final String CMD_QUERY_TODO = "CMD_QUERY_TODO";
	public static final String CMD_DEAL_TODO = "CMD_DEAL_TODO";
	public static final String CMD_DOWNLOAD_AD_ACTION = "CMD_DOWNLOAD_AD_ACTION";
	public static final String CMD_COMMIT_USERFACE = "CMD_COMMIT_USERFACE";
	public static final String CMD_DOWNLOAD_DEVFACE = "CMD_DOWNLOAD_DEVFACE";
	public static final String CMD_COMMIT_DEVFACE = "CMD_COMMIT_DEVFACE";
	public static final String CMD_DEVICE_ADMIN_ABORT = "CMD_DEVICE_ADMIN_ABORT";
	public static final String CMD_DEVICE_ADMIN_APPLY = "CMD_DEVICE_ADMIN_APPLY";
	public static final String CMD_DEVICE_INTEREST_ABORT = "CMD_DEVICE_INTEREST_ABORT";
	public static final String CMD_GET_LOCA_PARAM = "CMD_GET_LOCA_PARAM";
	public static final String CMD_SET_LOCA_PARAM = "CMD_SET_LOCA_PARAM";
	
	public static final String CMD_COMMIT_DEVICE_MOBILENUMBER = "CMD_COMMIT_DEVICE_MOBILENUMBER";
	public static final String CMD_COMMIT_CARE_REMINDER = "CMD_COMMIT_CARE_REMINDER";
	public static final String CMD_GET_CARE_REMINDER = "CMD_GET_CARE_REMINDER";	
	public static final String CMD_COMMIT_MEASURE_REMINDER = "CMD_COMMIT_MEASURE_REMINDER";
	public static final String CMD_GET_MEASURE_REMINDER = "CMD_GET_MEASURE_REMINDER";	
	public static final String CMD_COMMIT_DRUG_REMINDER = "CMD_COMMIT_DRUG_REMINDER";
	public static final String CMD_GET_DRUG_REMINDER = "CMD_GET_DRUG_REMINDER";
	public static final String CMD_GET_DEV_SUB_LIST = "CMD_GET_DEV_SUB_LIST";
	public static final String CMD_GET_DEV_SUB_INFO = "CMD_GET_DEV_SUB_INFO";

	public static final String CMD_COMMIT_GLYCOSE_SET = "CMD_COMMIT_GLYCOSE_SET";
	public static final String CMD_GET_GLYCOSE_SET = "CMD_GET_GLYCOSE_SET";	
	public static final String CMD_GET_GLYCOSE_DATA = "CMD_GET_GLYCOSE_DATA";
	public static final String CMD_GET_GLYCOSE_DATA_PERIOD = "CMD_GET_GLYCOSE_DATA_PERIOD";
	
	public static final String CMD_GET_BP_DATA_PERIOD = "CMD_GET_BP_DATA_PERIOD";
	
	
	public String mCmd;
	private JSONObject mJsonParam;
	private long time;
	private String mFilePath;
	
	public HTTPREQ(String cmd, String param) throws JSONException{
		mCmd = cmd;
		if(param != null)
			mJsonParam = new JSONObject(param);
		time = System.currentTimeMillis();
	}
	
	@Override
	public String toString(){
		return "{HTTPREQ:" + mCmd + "}";
	}
	
	public void setFilePath(String path){
		mFilePath = path;
	}
	
	public String getFilePath(){
		return mFilePath;
	}
	
	public boolean isLogInCmd(){
		return mCmd.equals(CMD_SIGN_IN);
	}
	
	public boolean isAllowedCmdWithoutLogIn(){
		if(isNeedSession()){
			return false;
		}else{
			return true;
		}
	}
	
	public boolean expired(){
		long cur = System.currentTimeMillis();
		if((cur - time) > 1000 * 20){
			Log.d("HTTPREQ", "expired:"+this);
			return true;
		}
		return false;
	}
	
	public boolean isNeedSession(){
		if(mCmd.equals(CMD_SIGN_IN) || mCmd.equals(CMD_VALIDATE_ACCOUNT) || mCmd.equals(CMD_GET_IDENTIFY_CODE)
		 || mCmd.equals(CMD_SIGN_UP) || mCmd.equals(CMD_RETRIEVE_PASSWORD)){
			return false;
		}
		return true;
	}
	
	public boolean isHttpUploadReq(){
		if(mCmd.equals(CMD_COMMIT_USERFACE) || mCmd.equals(CMD_COMMIT_DEVFACE)){
			return true;
		}
		return false;
	}
	
	public boolean isHttpDownloadReq(){
		if(mCmd.equals(CMD_DOWNLOAD_USERFACE) || mCmd.equals(CMD_DOWNLOAD_DEVFACE)
				|| mCmd.equals(CMD_DOWNLOAD_DEVFACE)){
			return true;
		}
		
		return false;
	}
	
	public String getUri(){
		if(mCmd.equals(CMD_VALIDATE_ACCOUNT)){
			return HttpConf.ValidateAccountUri();
		}
		
		if(mCmd.equals(CMD_GET_IDENTIFY_CODE)){
			return HttpConf.IdentifyCodeUri();
		}
		
		if(mCmd.equals(CMD_SIGN_UP)){
			return HttpConf.signUpUri();
		}
		
		if(mCmd.equals(CMD_SIGN_IN)){
			return HttpConf.signInUri();
		}
		
		if(mCmd.equals(CMD_CHANGE_PASSWORD)){
			return HttpConf.changePasswordUri();
		}
		
		if(mCmd.equals(CMD_RETRIEVE_PASSWORD)){
			return HttpConf.retrievePasswordUri();
		}
		
		if(mCmd.equals(CMD_GET_USERDATA)){
			return HttpConf.getUserDataUri();
		}
		
		if(mCmd.equals(CMD_CHECK_USERFACE)){
			return HttpConf.getUserFaceCheckUri();
		}
		
		if(mCmd.equals(CMD_GET_FA_DETAIL)){
			return HttpConf.getFamilyDetailUri();
		}
		
		if(mCmd.equals(CMD_GET_FA_LIST)){
			return HttpConf.getFamilyListUri();
		}
		
		if(mCmd.equals(CMD_GET_DEV_LIST)){
			return HttpConf.getDeviceListUri();
		}
		
		if(mCmd.equals(CMD_GET_DEV_SUB_LIST)){
			return HttpConf.getDeviceSubListUri();
		}
		
		if(mCmd.equals(CMD_GET_DEV_SUB_INFO)){
			return HttpConf.getDeviceSubInfoUri();
		}
		
		if(mCmd.equals(CMD_CHECK_DEVFACE)){
			return HttpConf.getDeviceFaceCheckUri();
		}
		
		if(mCmd.equals(CMD_GET_FAMEMBERS)){
			return HttpConf.getFamilyMembersUri();
		}
		
		if(mCmd.equals(CMD_COMMIT_USERDATA)){
			return HttpConf.getUserDataUpateUri();
		}
		
		if(mCmd.equals(CMD_COMMIT_BUILDFAMILY)){
			return HttpConf.getBuildFamilyUri();
		}
		
		if(mCmd.equals(CMD_APPLY_JOIN_FA)){
			return HttpConf.getApplyJoinFamilyUri();
		}
		
		if(mCmd.equals(CMD_COMMIT_ADMIN_FA)){
			return HttpConf.getFamilySetAdminUri();
		}
		
		if(mCmd.equals(CMD_COMMIT_ABORT_BY_ADMIN_FA)){
			return HttpConf.getFamilyAbortByAdminUri();
		}
		
		if(mCmd.equals(CMD_COMMIT_ABORT_BY_MEMBER_FA)){
			return HttpConf.getFamilyAbortByMemberUri();
		}
		
		if(mCmd.equals(CMD_COMMIT_FA_DETAIL)){
			return HttpConf.getUpdateFamilyDetailUri();
		}
		
		if(mCmd.equals(CMD_GET_DEVSETTINGS)){
			return HttpConf.getDeviceSettinsUri();
		}
		
		if(mCmd.equals(CMD_GET_DEVPOWER)){
			return HttpConf.getDevicePowerUri();
		}
		
		if(mCmd.equals(CMD_QUERY_LOCATION_PAGE)){
			return HttpConf.getQueryLocationPageUri();
		}
		
		/*if(mCmd.equals(CMD_QUERY_LOCATION_COUNT)){
			return HttpConf.getQueryLocationCountUri();
		}*/
		
		if(mCmd.equals(CMD_QUERY_LOCATION_NEWEST)){
			return HttpConf.getQueryLocationNewestUri();
		}
		
		if(mCmd.equals(CMD_ADD_NEW_DEVICE)){
			return HttpConf.getAddNewDeviceUri();
		}
		
		if(mCmd.equals(CMD_ACTIVATE_DEVICE)){
			return HttpConf.getActivateDeviceUri();
		}
		
		if(mCmd.equals(CMD_SET_LOCA_PARAM)){
			return HttpConf.getSetDeviceLocaParamUri();
		}
		
		if(mCmd.equals(CMD_UPDATE_DEVICE_NAME)){
			return HttpConf.getUpdateDeviceNameUri();
		}
		
		if(mCmd.equals(CMD_APPLY_INTEREST_DEV)){
			return HttpConf.getApplyInterestDeviceUri();
		}
		
		if(mCmd.equals(CMD_QUERY_TODO)){
			return HttpConf.getQueryToDoListUri();
		}
		
		if(mCmd.equals(CMD_DEAL_TODO)){
			return HttpConf.getDealToDoUri();
		}
		
		if(mCmd.equals(CMD_DOWNLOAD_AD_ACTION)){
			return HttpConf.getDownloadADUri();
		}
			
		if(mCmd.equals(CMD_COMMIT_USERFACE)){
			return HttpConf.getUpdateUserFaceUri();
		}
		
		if(mCmd.equals(CMD_DOWNLOAD_USERFACE)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String type = mJsonParam.getString("type");
					return HttpConf.getDownloadUserFaceUri(uid, type);
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		if(mCmd.equals(CMD_DOWNLOAD_DEVFACE)){
			if(mJsonParam != null){
				try {
					String tid = mJsonParam.getString("tid");
					String type = mJsonParam.getString("type");
					return HttpConf.getDownloadDeviceFaceUri(tid, type);
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		if(mCmd.equals(CMD_COMMIT_DEVFACE)){
			return HttpConf.getUpdateDevFaceUri();
		}
		
		if(mCmd.equals(CMD_DEVICE_ADMIN_ABORT)){
			return HttpConf.getDeviceAbortAdminUri();
		}
		
		if(mCmd.equals(CMD_DEVICE_ADMIN_APPLY)){
			return HttpConf.getDeviceApplyAdminUri();
		}
		
		if(mCmd.equals(CMD_DEVICE_INTEREST_ABORT)){
			return HttpConf.getDeviceAbortInterestUri();
		}
		
		if(mCmd.equals(CMD_GET_LOCA_PARAM)){
			return HttpConf.getQueryDeviceLocaParamUri();
		}
		
		if(mCmd.equals(CMD_COMMIT_DEVICE_MOBILENUMBER)){
			return HttpConf.getUpdateDeviceMobileNumberUri();
		}
		
		if(mCmd.equals(CMD_COMMIT_CARE_REMINDER)){
			return HttpConf.setCareRminderUri();
		}	
		
		if(mCmd.equals(CMD_GET_CARE_REMINDER)){
			return HttpConf.getCareRminderUri();
		}
		
		if(mCmd.equals(CMD_COMMIT_MEASURE_REMINDER)){
			return HttpConf.setMeasureRminderUri();
		}	
		
		if(mCmd.equals(CMD_GET_MEASURE_REMINDER)){
			return HttpConf.getMeasureRminderUri();
		}
		
		if(mCmd.equals(CMD_COMMIT_DRUG_REMINDER)){
			return HttpConf.setDrugRminderUri();
		}	
		
		if(mCmd.equals(CMD_GET_DRUG_REMINDER)){
			return HttpConf.getDrugRminderUri();
		}		
		
		if(mCmd.equals(CMD_COMMIT_GLYCOSE_SET)){
			return HttpConf.setGlycoseSetUri();
		}	
		
		if(mCmd.equals(CMD_GET_GLYCOSE_SET)){
			return HttpConf.getGlycoseSetUri();
		}	
		
		if(mCmd.equals(CMD_GET_GLYCOSE_DATA)){
			return HttpConf.getGlycoseDataUri();
		}
		
		if(mCmd.equals(CMD_GET_GLYCOSE_DATA_PERIOD)){
			return HttpConf.getGlycoseDatapageUri();
		}		
		
		if(mCmd.equals(CMD_GET_BP_DATA_PERIOD)){
			return HttpConf.getBpDatapageUri();
		}

		return null;
	}
	
	public String getStamp() throws JSONException{
		if(mJsonParam != null){
			return mJsonParam.getString("stamp");
		}
		return null;
	}
	
	public JSONObject createSendData(boolean toRemote){
		if(mCmd.equals(CMD_VALIDATE_ACCOUNT)){
			if(mJsonParam != null){
				try {
					String account = mJsonParam.getString("account");
					JSONObject sd = new JSONObject();
					sd.put("username", account);
					return sd;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		if(mCmd.equals(CMD_GET_IDENTIFY_CODE)){
			if(mJsonParam != null){
				try {
					String phone = mJsonParam.getString("phone");
					JSONObject sd = new JSONObject();
					sd.put("usermobileno", phone);
					return sd;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		if(mCmd.equals(CMD_SIGN_UP)){
			if(mJsonParam != null){
				try {
					String phone = mJsonParam.getString("phone");
					String user = mJsonParam.getString("user");
					String pwd = mJsonParam.getString("password");
					if(toRemote){
						pwd = RSAUtils.Encrypt(pwd);
						Log.d("NetService", "SIGN_UP:pwd="+pwd);
					}
						//String test = RSAUtils.Decrypt(encrypt);
						//Log.d("NetService", "SIGN_UP:dectypt pwd="+test);
					String code = mJsonParam.getString("idcode");
					JSONObject sd = new JSONObject();
					sd.put("usermobileno", phone);
					sd.put("username", user);
					sd.put("password", pwd);
					sd.put("validcode", code);
					return sd;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		if(mCmd.equals(CMD_SIGN_IN)){
			if(mJsonParam != null){
				try {
					
					/*Time time = new Time();
					time.setToNow();
					String dateTime = String.format("%04d%02d%02d%02d%02d%02d", time.year,time.month+1,
							time.monthDay,time.hour,time.minute,time.second);*/
					long systime = System.currentTimeMillis();
					//String sTime = String.valueOf(systime);
					String user = mJsonParam.getString("user");
					String pwd = mJsonParam.getString("password");
					if(toRemote){
						pwd = RSAUtils.Encrypt(pwd);
						Log.d("NetService", "SIGN_IN:pwd="+pwd);
						//String test = RSAUtils.Decrypt(encrypt);
						//Log.d("NetService", "SIGN_IN:dectypt pwd="+test);
					}
					
					JSONObject sd = new JSONObject();
					sd.put("loginname", user);
					sd.put("password", pwd);
					sd.put("logintime", systime);
					return sd;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		if(mCmd.equals(CMD_CHANGE_PASSWORD)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String oldpwd = mJsonParam.getString("oldpassword");
					String newpwd = mJsonParam.getString("newpassword");
					if(toRemote){
						oldpwd = RSAUtils.Encrypt(oldpwd);
						newpwd = RSAUtils.Encrypt(newpwd);
						//Log.d("NetService", "SIGN_IN:pwd="+pwd);
						//String test = RSAUtils.Decrypt(encrypt);
						//Log.d("NetService", "SIGN_IN:dectypt pwd="+test);
					}
					JSONObject sd = new JSONObject();
					sd.put("uid", uid);
					sd.put("oldpassword", oldpwd);
					sd.put("newpassword", newpwd);
					return sd;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} 
			}
		}
		
		if(mCmd.equals(CMD_RETRIEVE_PASSWORD)){
			if(mJsonParam != null){
				try {
					String phone = mJsonParam.getString("phone");
					JSONObject sd = new JSONObject();
					sd.put("usermobileno", phone);
					return sd;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		if(mCmd.equals(CMD_GET_USERDATA)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					JSONObject sd = new JSONObject();
					sd.put("uid", uid);
					return sd;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		if(mCmd.equals(CMD_CHECK_USERFACE)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String vuid = mJsonParam.getString("vuid");
					long vstamp = mJsonParam.getLong("vstamp");
					JSONObject sd = new JSONObject();
					sd.put("uid", uid);
					sd.put("validuid", vuid);
					sd.put("timestamp", vstamp);
					return sd;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		if(mCmd.equals(CMD_GET_FA_LIST)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					JSONObject sd = new JSONObject();
					sd.put("uid", uid);
					return sd;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		if(mCmd.equals(CMD_GET_DEV_LIST)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					JSONObject sd = new JSONObject();
					sd.put("uid", uid);
					return sd;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		if(mCmd.equals(CMD_GET_DEV_SUB_LIST)){
			if(mJsonParam != null){
				try {
					String tid = mJsonParam.getString("tid");
					JSONObject sd = new JSONObject();
					sd.put("tid", tid);
				
					return sd;
				} catch (JSONException e) {
					// TODO: handle exception
					e.printStackTrace();
				}
			}
		}
		
		if(mCmd.equals(CMD_GET_DEV_SUB_INFO)){
			if(mJsonParam != null){
				try {
					String tid = mJsonParam.getString("tid");
					String subcode = mJsonParam.getString("subcode");
					String table = mJsonParam.getString("table");
					JSONObject sd = new JSONObject();
					sd.put("tid", tid);
					sd.put("subcode", subcode);
					if(!toRemote){
						sd.put("table", table);
					}
					return sd;
				} catch (JSONException e) {
					// TODO: handle exception
					e.printStackTrace();
				}
			}
		}
		
		if(mCmd.equals(CMD_CHECK_DEVFACE)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String vtid = mJsonParam.getString("vtid");
					long lstamp = mJsonParam.getLong("vstamp");
					JSONObject sd = new JSONObject();
					sd.put("uid", uid);
					sd.put("validtid", vtid);
					sd.put("timestamp", lstamp);
					return sd;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		if(mCmd.equals(CMD_GET_FAMEMBERS)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String fid = mJsonParam.getString("fid");
					JSONObject sd = new JSONObject();
					sd.put("uid", uid);
					sd.put("fid", fid);
					return sd;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		if(mCmd.equals(CMD_COMMIT_USERDATA)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String ac = mJsonParam.getString("username");
					String mobile = mJsonParam.getString("mobileno");
					String nick = mJsonParam.getString("nickname");
					String idcard = mJsonParam.getString("useridcardno");
					String gender = mJsonParam.getString("gender");
					String addr = mJsonParam.getString("residentialaddress");
					String edu = mJsonParam.getString("educationid");
					String city = mJsonParam.getString("cityid");
					String occu = mJsonParam.getString("occupationid");
					String pos = mJsonParam.getString("positionid");
					
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("username", ac);
    				if(!toRemote){
    					sd.put("mobileno", mobile);
    				}
    				sd.put("nickname", nick);
    				sd.put("useridcardno", idcard);
    				sd.put("gender", gender);
    				sd.put("residentialaddress", addr);
    				sd.put("educationid", edu);
    				sd.put("cityid", city);
    				sd.put("occupationid", occu);
    				sd.put("positionid", pos);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_COMMIT_BUILDFAMILY)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String name = mJsonParam.getString("familyname");
					String status = mJsonParam.getString("familystatus");
					String admin = mJsonParam.getString("admin");
					
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("familyname", name);
    				sd.put("familystatus", status);
    				sd.put("admin", admin);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_APPLY_JOIN_FA)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String fid = mJsonParam.getString("fid");
					String status = mJsonParam.getString("familystatus");
					
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("fid", fid);
    				sd.put("familystatus", status);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_COMMIT_ADMIN_FA)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String fid = mJsonParam.getString("fid");
					String adminuid = mJsonParam.getString("adminuid");
					String oldadminuid = mJsonParam.getString("oldadminuid");
					
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("fid", fid);
    				sd.put("adminuid", adminuid);
    				if(!toRemote){
    					sd.put("oldadminuid", oldadminuid);
    				}
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_COMMIT_ABORT_BY_ADMIN_FA)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String fid = mJsonParam.getString("fid");
					JSONArray uidarray = mJsonParam.getJSONArray("uidarray");
					
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("fid", fid);
    				sd.put("uidarray", uidarray);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if (mCmd.equals(CMD_COMMIT_ABORT_BY_MEMBER_FA)) {
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String fid = mJsonParam.getString("fid");
					
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("fid", fid);
    				return sd;
				} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_GET_FA_DETAIL)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String fid = mJsonParam.getString("fid");
					JSONObject sd = new JSONObject();
					sd.put("uid", uid);
					sd.put("fid", fid);
					return sd;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		if(mCmd.equals(CMD_COMMIT_FA_DETAIL)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String fid = mJsonParam.getString("fid");
					String familyname = mJsonParam.getString("familyname");
					String familyaddress = mJsonParam.getString("familyaddress");
					String familyphoneno = mJsonParam.getString("familyphoneno");
					
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("fid", fid);
    				sd.put("familyname", familyname);
    				sd.put("familyaddress", familyaddress);
    				sd.put("familyphoneno", familyphoneno);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_GET_DEVSETTINGS)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String tid = mJsonParam.getString("tid");
					
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("tid", tid);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_GET_DEVPOWER)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					JSONArray tidarr = mJsonParam.getJSONArray("tidarr");
					
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("tidarr", tidarr);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_QUERY_LOCATION_PAGE)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String tid = mJsonParam.getString("tid");
					long s = mJsonParam.getLong("starttime");
					long e = mJsonParam.getLong("endtime");
					String pageindex = mJsonParam.getString("pageindex");
					String pagesize = mJsonParam.getString("pagesize");
					
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("tid", tid);
    				sd.put("starttime",s);
    				sd.put("endtime", e);
    				sd.put("pageindex", pageindex);
    				sd.put("pagesize", pagesize);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
	/*	if(mCmd.equals(CMD_QUERY_LOCATION_COUNT)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String tid = mJsonParam.getString("tid");
					String count = mJsonParam.getString("count");
					
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("tid", tid);
    				sd.put("count",count);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}*/
		
		if(mCmd.equals(CMD_QUERY_LOCATION_NEWEST)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String tid = mJsonParam.getString("tid");
					String maxrecord = mJsonParam.getString("maxrecord");
					long fromtimetonow = mJsonParam.getLong("fromtimetonow");
					
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("tid", tid);
    				sd.put("maxrecord",maxrecord);
    				sd.put("fromtimetonow", fromtimetonow);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_ADD_NEW_DEVICE)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String did = mJsonParam.getString("did");
					//String fid = mJsonParam.getString("fid");
					String devicename = mJsonParam.getString("devicename");
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("did", did);
    				sd.put("tid", "");
    				sd.put("fid","");
    				sd.put("devicename", devicename);
    				//JSONArray types = new JSONArray("[\"" + DEV_DATA.TYPE_LOCATE + "\"]");
    				//sd.put("devicetypearray", types);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_ACTIVATE_DEVICE)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String tid = mJsonParam.getString("tid");
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("tid", tid);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_SET_LOCA_PARAM)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String tid = mJsonParam.getString("tid");
					String fence = mJsonParam.getString("fence");
					String range = mJsonParam.getString("range");
					String lat = mJsonParam.getString("lat");
					String lng = mJsonParam.getString("lng");
					String rate = mJsonParam.getString("rate");
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("tid", tid);
    				sd.put("fence", fence);
    				sd.put("range", range);
    				sd.put("lat", lat);
    				sd.put("lng", lng);
    				sd.put("rate", rate);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_UPDATE_DEVICE_NAME)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String tid = mJsonParam.getString("tid");
					String devicename = mJsonParam.getString("devicename");
					
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("tid", tid);
    				sd.put("devicename", devicename);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_APPLY_INTEREST_DEV)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String did = mJsonParam.getString("did");
					String tid = mJsonParam.getString("tid");
					String interestuid = mJsonParam.getString("interestuid");
					String devicename = mJsonParam.getString("devicename");
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("did", did);
    				sd.put("tid", tid);
    				sd.put("interestuid",interestuid);
    				sd.put("devicename", devicename);
    				//JSONArray types = new JSONArray("[\"" + DEV_DATA.TYPE_LOCATE + "\"]");
    				//sd.put("devicetypearray", types);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_QUERY_TODO)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_DEAL_TODO)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String rid = mJsonParam.getString("rid");
					String rembercode = mJsonParam.getString("rembercode");
					String remberstate = mJsonParam.getString("remberstate");
					long rembertime = mJsonParam.getLong("rembertime");
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				JSONObject e = new JSONObject();
    				e.put("rid", rid);
    				e.put("rembercode", rembercode);
    				e.put("remberstate", remberstate);
    				e.put("rembertime", rembertime);
    				JSONArray arr = new JSONArray();
    				arr.put(e);
    				sd.put("remberarr", arr);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_DOWNLOAD_AD_ACTION)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					JSONArray tidArray = mJsonParam.getJSONArray("tidarray");
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("tidarray", tidArray);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_COMMIT_USERFACE)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_DOWNLOAD_USERFACE)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String type = mJsonParam.getString("type");
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("type", type);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_DOWNLOAD_DEVFACE)){
			if(mJsonParam != null){
				try {
					String tid = mJsonParam.getString("tid");
					String type = mJsonParam.getString("type");
					JSONObject sd = new JSONObject();
    				sd.put("tid", tid);
    				sd.put("type", type);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}	
		}
		
		if(mCmd.equals(CMD_COMMIT_DEVFACE)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String tid = mJsonParam.getString("tid");
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("tid", tid);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_DEVICE_ADMIN_ABORT)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String tid = mJsonParam.getString("tid");
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("tid", tid);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_DEVICE_ADMIN_APPLY)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String tid = mJsonParam.getString("tid");
					String devicename = mJsonParam.getString("devicename");
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("did", "");
    				sd.put("tid", tid);
    				sd.put("fid","");
    				sd.put("devicename", devicename);
    				
    				//JSONArray types = new JSONArray();
    				//sd.put("devicetypearray", types);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_DEVICE_INTEREST_ABORT)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String tid = mJsonParam.getString("tid");
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("tid", tid);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_GET_LOCA_PARAM)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String tid = mJsonParam.getString("tid");
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("tid", tid);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_COMMIT_DEVICE_MOBILENUMBER)){
			if(mJsonParam != null){
				try {
					String uid = mJsonParam.getString("uid");
					String tid = mJsonParam.getString("tid");
					String simno = mJsonParam.getString("simno");
					JSONObject sd = new JSONObject();
    				sd.put("uid", uid);
    				sd.put("tid", tid);
    				sd.put("simno", simno);
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_COMMIT_CARE_REMINDER)){
			if(mJsonParam != null){
				try {

					JSONObject sd = new JSONObject();

    				sd.put("uid", mJsonParam.getString("uid"));
    				sd.put("tid", mJsonParam.getString("tid"));
    				sd.put("terminaltype", mJsonParam.getString("terminaltype"));
    				sd.put("opt", mJsonParam.getString("opt"));
    				sd.put("dex", mJsonParam.getString("dex"));
    				sd.put("updatetime", mJsonParam.getLong("updatetime"));
    				sd.put("remind", mJsonParam.getString("remind"));
    				sd.put("remindmsg", mJsonParam.getString("remindmsg"));
    				sd.put("remindmode", mJsonParam.getString("remindmode"));
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_COMMIT_DRUG_REMINDER)){
			if(mJsonParam != null){
				try {

					JSONObject sd = new JSONObject();

    				sd.put("uid", mJsonParam.getString("uid"));
    				sd.put("tid", mJsonParam.getString("tid"));
    				sd.put("terminaltype", mJsonParam.getString("terminaltype"));
    				sd.put("opt", mJsonParam.getString("opt"));
    				sd.put("dex", mJsonParam.getString("dex"));
    				sd.put("updatetime", mJsonParam.getLong("updatetime"));
    				sd.put("remind", mJsonParam.getString("remind"));
    				sd.put("remindmsg", mJsonParam.getString("remindmsg"));
    				sd.put("remindmode", mJsonParam.getString("remindmode"));
    				sd.put("subcode", mJsonParam.getString("subcode"));
    				sd.put("drugarr", mJsonParam.getJSONArray("drugarr"));    				
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}	
		
		if(mCmd.equals(CMD_COMMIT_MEASURE_REMINDER)){
			if(mJsonParam != null){
				try {

					JSONObject sd = new JSONObject();

    				sd.put("uid", mJsonParam.getString("uid"));
    				sd.put("tid", mJsonParam.getString("tid"));
    				sd.put("terminaltype", mJsonParam.getString("terminaltype"));
    				sd.put("opt", mJsonParam.getString("opt"));
    				sd.put("dex", mJsonParam.getString("dex"));
    				sd.put("updatetime", mJsonParam.getLong("updatetime"));
    				sd.put("remind", mJsonParam.getString("remind"));
    				sd.put("remindmsg", mJsonParam.getString("remindmsg"));
    				sd.put("remindmode", mJsonParam.getString("remindmode"));
    				sd.put("subcode", mJsonParam.getString("subcode"));				
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_GET_CARE_REMINDER) || mCmd.equals(CMD_GET_MEASURE_REMINDER) || mCmd.equals(CMD_GET_DRUG_REMINDER)){
			if(mJsonParam != null){
				try {

					JSONObject sd = new JSONObject();

    				sd.put("uid", mJsonParam.getString("uid"));
    				sd.put("tid", mJsonParam.getString("tid"));
    				sd.put("terminaltype", mJsonParam.getString("terminaltype"));
    				sd.put("dex", mJsonParam.getString("dex"));

    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}				

		if(mCmd.equals(CMD_COMMIT_GLYCOSE_SET)){
			if(mJsonParam != null){
				try {

					JSONObject sd = new JSONObject();

    				sd.put("uid", mJsonParam.getString("uid"));
    				sd.put("tid", mJsonParam.getString("tid"));
       		       sd.put("unit", mJsonParam.getString("unit"));
       		       sd.put("voice", mJsonParam.getString("voice"));
       		       sd.put("glycosylated", mJsonParam.getString("glycosylated"));
       		       sd.put("beforelow", mJsonParam.getString("beforelow"));
       		       sd.put("beforeupper", mJsonParam.getString("beforeupper"));
       		       sd.put("afterlow", mJsonParam.getString("afterlow"));
       		       sd.put("afterupper", mJsonParam.getString("afterupper"));
       		       sd.put("bedtimelow", mJsonParam.getString("bedtimelow"));
       		       sd.put("bedtimeupper", mJsonParam.getString("bedtimeupper"));
       		       sd.put("dawnlow", mJsonParam.getString("dawnlow"));
       		       sd.put("dawnupper", mJsonParam.getString("dawnupper"));    				

    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}	
		
		if(mCmd.equals(CMD_GET_GLYCOSE_SET)){
			if(mJsonParam != null){
				try {

					JSONObject sd = new JSONObject();

    				sd.put("uid", mJsonParam.getString("uid"));
    				sd.put("tid", mJsonParam.getString("tid"));               	
    				
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}
		
		if(mCmd.equals(CMD_GET_GLYCOSE_DATA)){
			if(mJsonParam != null){
				try {

					JSONObject sd = new JSONObject();

    				sd.put("uid", mJsonParam.getString("uid"));
    				sd.put("tid", mJsonParam.getString("tid")); 
    				sd.put("subcode", mJsonParam.getString("subcode")); 
    				sd.put("fromtimetonow", mJsonParam.getString("fromtimetonow")); 
    				sd.put("pageindex", mJsonParam.getString("pageindex")); 
    				sd.put("pagesize", mJsonParam.getString("pagesize"));     				
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}		
		
		if(mCmd.equals(CMD_GET_GLYCOSE_DATA_PERIOD)){
			if(mJsonParam != null){
				try {

					JSONObject sd = new JSONObject();

    				sd.put("uid", mJsonParam.getString("uid"));
    				sd.put("tid", mJsonParam.getString("tid")); 
    				sd.put("subcode", mJsonParam.getString("subcode")); 
    				sd.put("starttime", mJsonParam.getString("starttime")); 
    				sd.put("endtime", mJsonParam.getString("endtime"));     				
    				sd.put("pageindex", mJsonParam.getString("pageindex")); 
    				sd.put("pagesize", mJsonParam.getString("pagesize"));     				
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}			
		
		if(mCmd.equals(CMD_GET_BP_DATA_PERIOD)){
			if(mJsonParam != null){
				try {

					JSONObject sd = new JSONObject();

    				sd.put("uid", mJsonParam.getString("uid"));
    				sd.put("tid", mJsonParam.getString("tid")); 
    				sd.put("subcode", mJsonParam.getString("subcode")); 
    				sd.put("starttime", mJsonParam.getString("starttime")); 
    				sd.put("endtime", mJsonParam.getString("endtime"));     				
    				sd.put("pageindex", mJsonParam.getString("pageindex")); 
    				sd.put("pagesize", mJsonParam.getString("pagesize"));     				
    				return sd;
    			} catch (JSONException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
			}
		}

		return null;
	}
	
	public JSONObject createJSONEntity(){
		JSONObject sd = createSendData(true);
		if(sd == null){
			Log.e("NET_DEBUG", mCmd + "createSendData failed!");
		}
		if(sd != null){
			try {
				JSONObject ret = new JSONObject();
				ret.put("senddata", sd);
				return ret;
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}
}
